package com.yu.waterstation.system.modules.app.service.impl;

import com.yu.waterstation.common.entity.app.TicketGoods;
import com.yu.waterstation.system.modules.app.mapper.TicketGoodsMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TicketGoodsService {
    @Resource
    private TicketGoodsMapper ticketGoodsMapper;

    public List<TicketGoods> listGoods() {
        return ticketGoodsMapper.selectList(null);
    }

    @Transactional(rollbackFor = Exception.class)
    public int insertGoods(TicketGoods goods) {
        return ticketGoodsMapper.insert(goods);
    }

    @Transactional(rollbackFor = Exception.class)
    public int updateGoodsById(TicketGoods goods) {
        return ticketGoodsMapper.updateById(goods);
    }

    @Transactional(rollbackFor = Exception.class)
    public int deleteGoodsById(Integer goodsId) {
        return ticketGoodsMapper.deleteById(goodsId);
    }

    @Transactional(rollbackFor = Exception.class)
    public int updateSellStatus(Integer goodsId, Boolean status) {
        TicketGoods goods = new TicketGoods();
        goods.setId(goodsId);
        goods.setSellStatus(status);
        return ticketGoodsMapper.updateById(goods);
    }
}
